import matplotlib.pyplot as plt
import math

x = []
saves = []
loads = []
start = 0
newi = True
i = 1
for line in open('result'):
    if newi:
        x.append(i)
        i += 1
        saves.append(float(line))
        newi = False
    else:
        loads.append(float(line))
        newi = True
print(len(x))
print(len(saves))
print(len(loads))

print(sum(saves)/len(x))
print(sum(loads)/len(x))
print(max(saves), min(saves))
print(max(loads), min(loads))

fig, ax = plt.subplots()
ax.bar(x, saves, label='Save',edgecolor = "none")
ax.bar(x, loads, bottom=saves,edgecolor = "none",label='Load',color='r')
# ax.plot(x, saves)
# ax.plot(x, loads)
ax.set_xlabel('Rule id')
ax.set_ylabel('Time (ns)')
ax.legend()
plt.show()

# print(1 - sum(y)/sum(y1))
# udp_size = []
# c_size = []
# for i in range(0, 8):
#     c_size.append(math.pow(2, i) * 10 + 8)
#     udp_size.append(math.pow(2, i) * 10 + 46)


# print(1 - sum(c_size)/sum(udp_size))